package n27;

public class Main {
    public static int removeElement(int[] nums, int val) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        // 使用双指针法
        int fast = 0, slow = 0;
        while (fast < nums.length) {
            if (nums[fast]!=val){
                nums[slow] = nums[fast];
                ++slow;
            }
            ++fast;
        }
        return  slow;
    }

    public static void main(String[] args) {
        // int[] nums = {3,2,2,3};
        int[] nums = {0,1,2,2,3,0,4,2};
        int num = removeElement(nums,3);
        for (int i = 0; i < num; i++) {
            System.out.println(nums[i]);
        }
    }

}
